<!--
  // Creation History
  // --------------------------------------------------------------
  //	NAME:			AllProjectReport.jsp
  //	TITLE:			
  //	FUNCTION:		
  //	BY:				Beyes Xia
  //	DATE:			2004-2-12 12:50
  //	Update BY:		Beyes Xia
  //	Update DATE:	2004-4-21 10:54  
  // --------------------------------------------------------------
-->

<%@ include file="../tssheader.jsp" %>
<%@ page import="tss.options.*" %>
<script Language="Javascript" src="<%=contextPath%>/tss/projectchargeablereport/Calendar1-821.js"></script>
<%
    try
    {
	CompanyOptions companyOptions = new CompanyOptions();
	ProjectCategoryOptions pco = new ProjectCategoryOptions();
    GroupOptions pgo = new GroupOptions();    

//--------------- 2004-4-21 10:54 Update By Beyes ----------------//
//	YearOptions yearFrom = new YearOptions();
//	MonthOptions monthFrom = new MonthOptions();
//    YearOptions yearTo = new YearOptions();
//	MonthOptions monthTo = new MonthOptions();
//----------------------------------------------------------------//
	
	String strCondition = session.getAttribute("s_condition")==null?"":(String)session.getAttribute("s_condition");
	String strType = session.getAttribute("s_type")==null?"":(String)session.getAttribute("s_type");

//System.out.println("strCondition="+strCondition);
//System.out.println("strType="+strType);

    String project_category = session.getAttribute("project_category")==null?"":(String)session.getAttribute("project_category");
    String group = session.getAttribute("group")==null?"":(String)session.getAttribute("group");    
	String company = (String)session.getAttribute("company");

//--------------- 2004-4-21 10:54 Update By Beyes ----------------//
	String str_dateFrom = session.getAttribute("s_date_from")==null?"":(String)session.getAttribute("s_date_from");
	String str_dateTo = session.getAttribute("s_date_to")==null?"":(String)session.getAttribute("s_date_to");	

//  String str_year_from = session.getAttribute("year_from")==null?"":(String)session.getAttribute("year_from");
//	String str_month_from = session.getAttribute("month_from")==null?"":(String)session.getAttribute("month_from");
//	String str_year_to = session.getAttribute("year_to")==null?"":(String)session.getAttribute("year_to");
//	String str_month_to = session.getAttribute("month_to")==null?"":(String)session.getAttribute("month_to");
//----------------------------------------------------------------//	
	
//	System.out.println("pco.getoptions :"+pco.getOptions(project_category));
//	System.out.println("pgo.getoptions :"+pgo.getOptions(group));	
	char[] co = pco.getOptions(project_category).toCharArray();
	char[] go = pgo.getOptions(group).toCharArray();
	String categoryOptions = "";
	String groupOptions = "";
	for(int i=0;i<co.length;i++)
	{	
		if(co[i]!='\n')
			categoryOptions += co[i];
	}
	for(int i=0;i<go.length;i++)
	{	
		if(go[i]!='\n')
			groupOptions += go[i];
	}
//	System.out.println("categoryOptions :"+categoryOptions);
//	System.out.println("groupOptions :"+groupOptions);	
		
%>
<script language="JavaScript1.1">
//--------------- 2004-4-21 10:54 Update By Beyes ----------------//
function tss_calendar_from()
{
	var today = new Date();
	show_calendar('fm.date_from', today.getMonth(), today.getYear(), 'YYYY-MM-DD');
}
function tss_calendar_to()
{
	var today = new Date();
	show_calendar('fm.date_to', today.getMonth(), today.getYear(), 'YYYY-MM-DD');
}
function checkFromTO()
{
	if(fm.date_from.value.length!=0 && fm.date_to.value.length!=0 && fm.date_from.value>fm.date_to.value)
	{
		alert("Date From must be earlier than Date To");
		return false;
	}
	return true;
}
function checkDate(object) 
{
	var obj=object;
	var d = obj.value;
	var d1 = fm.type.value;
	if(d1 == 'd' && d.length == 0)
	{
		alert("Please input correct date with format as YYYY-MM-DD.");
		return false;
	}	
	if(d.length !=0 && d.length !=10)
	{
		alert("Please input correct date with format as YYYY-MM-DD.");
		return false;
	}	
	if(d.length==10)
	{
		if (d.substring(4,5)!="-" || d.substring(7,8)!="-") 
		{
			alert("Please input correct date with format as YYYY-MM-DD.");
			return false;
		}
		var day = d.substring(8,10);
		var month = d.substring(5,7);
		var year = d.substring(0,4);
		if (day==null || isNaN(day)) 
		{
			alert("Please input correct date with format as YYYY-MM-DD.");
			return false;
		}
		if (month==null || isNaN(month)) 
		{
			alert("Please input correct date with format as YYYY-MM-DD.");
			return false;
		}
		if (day==null || isNaN(day)) 
		{
			alert("Please input correct date with format as YYYY-MM-DD.");
			return false;
		}
		if (day < 1 || day > 31)
		{
			alert("Please input correct date with format as YYYY-MM-DD.");
			return false;
		}
		if (month < 1 || month > 12) 
		{
			alert("Please input correct date with format as YYYY-MM-DD.");
			return false;
		}
		if ((month==4 || month==6 || month==9 || month==11) && day==31) 
		{
			alert("Please input correct date with format as YYYY-MM-DD.");
			return false;
		}
		if (month == 2) 
		{
			var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
			if (day > 29 || (day==29 && !isleap))
			{
				alert("Please input correct date with format as YYYY-MM-DD.");
				return false;
			}
		} 
	}
	return true;
}
function mysubmit()
{
	if(checkDate(fm.date_from) && checkDate(fm.date_to) && checkFromTO())
	{
		fm.submit();
	}
}
/*
function formValidation()
{
	var d1 = fm.year_from.value;
	var d2 = fm.month_from.value;
	var d3 = fm.year_to.value;
	var d4 = fm.month_to.value;
	var d6 = fm.type.value;
	if ((d1.length==0 && d2.length!=0)||(d1.length!=0 && d2.length==0))
	{
		alert("Year and Month should be related!");
		return false;
	}
	if ((d3.length==0 && d4.length!=0)||(d3.length!=0 && d4.length==0))
	{
		alert("Year and Month should be related!");
		return false;
	}
	if (d1.length != 0 && d2.length != 0 && d3.length != 0 && d4.length != 0 && (d1>d3 || (d1==d3 && d2>d4)))
	{
		alert("Date From must be earlier then Date To!");
		return false;
	}
	if(d6 == 'd' && (d1.length == 0 || d2.length ==0 || d3.length ==0 || d4.length ==0))
	{
		alert("Year and Month should be select!");
		return false;
	}		
	return true;
}
function mysubmit()
{
	if(formValidation())
	{
		fm.submit();
	}
}
*/
//----------------------------------------------------------------//
function showLay()
{
	var d5 = fm.condition.value;
	if (d5 == 'c')
	{
		showText.innerHTML='&nbsp;Project Category:';
		optionHtml.innerHTML='<select name="cOrg_name"><%=categoryOptions%></select>';
	}
	if (d5 == 'g')
	{
		showText.innerHTML='&nbsp;Project Group:';
		optionHtml.innerHTML='<select name="cOrg_name"><%=groupOptions%></select>';			
	}
}
function init()
{
	var d5 = fm.condition.value;
	if (d5 == 'c')
	{
		showText.innerHTML='&nbsp;Project Category:';
		optionHtml.innerHTML='<select name="cOrg_name"><%=categoryOptions%></select>';
	}
	if (d5 == 'g')
	{
		showText.innerHTML='&nbsp;Project Group:';
		optionHtml.innerHTML='<select name="cOrg_name"><%=groupOptions%></select>';			
	}
}
function myCancel()
{
	fm.date_from.value="";
	fm.date_to.value="";
	fm.cOrg_name.value="";
}
</script>
<body onLoad=init()>

<h2>Project Chargeable Report</h2>
<form id=fm method=post action=<%=contextPath%>/servlet/tss.projectchargeablereport.ProjectChargeable >

<table border=1 cellspacing=0 cellpadding="10" width="450">
<tr>
<td>
<table border=0>
<tr>
	<td>Condition:</td>
	<td>
		<select name="condition" onchange=showLay()>
			<!--<option value = p>Project</option>-->
			<option value = c <%=strCondition.equals("c")?"selected":""%> >Project Category</option>
			<option value = g <%=strCondition.equals("g")?"selected":""%> >Project Group</option>
		</select>
	</td>
	<td>&nbsp;Type:</td>
	<td>
		<select name="type">
			<option value = s <%=strType.equals("s")?"selected":""%> >Summary</option>
			<option value = d <%=strType.equals("d")?"selected":""%> >Detail</option>
		</select>
	</td>
</tr>
</table>
</td>
</tr>
</table>

<br>

<table border=1 cellspacing=0 cellpadding="10" width="450">
<tr>
<td>
<table border=0>
<tr>
	<td nowrap>Cost Center:</td>
	<td>
		<select name='company_code'>
		<%=companyOptions.getDefualtOptions(company)%>
		</select>
	</td>
	<td nowrap>
	<span id="showText">&nbsp;Project Category:</span>
	<span id="optionHtml">
		<select name="cOrg_name">			
			<%=categoryOptions%>			
		</select>
	</span>
	</td>
</tr>
<tr>
	<td nowrap>Date Range:</td>
	<td nowrap colspan=2>
	From &nbsp;
	<input type=text name='date_from'  maxlength=10  align='left' value='<%= str_dateFrom %>'>
	<input type=button name=but_cal onClick="tss_calendar_from();" value='...'>(YYYY-MM-DD)*
	</td>
</tr>
<tr>
	<td>&nbsp;</td>
	<td nowrap colspan=2>To &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	<input type=text name='date_to'  maxlength=10  align='left' value='<%= str_dateTo %>'>
	<input type=button name=but_cal1 onClick="tss_calendar_to();" value='...'>(YYYY-MM-DD)*
	</td>
</tr>
</table>
</td>
</tr>
</table>

<br>
<hr>
<p>
	<INPUT type=button value=Export onclick="mysubmit()">
	<INPUT type=button value=Cancel onclick='myCancel()'>	
</p>
</form>
<%  }catch(Exception e) {
	out.println(e.toString());
}%>
<%@ include file="../tssfooter.jsp" %>
</body>
</html>

